/**
 * Smart City use case October 2012 
 */
package com.orange.smartcity.android;

import com.orange.smartcity.android.tools.GpsLocationUtils;
import com.orange.smartcity.android.tools.ImageLoaderUtils;


import android.app.Application;
import android.content.Context;
import android.os.StrictMode;


/**
 * @author GQXG9096
 *
 */
public class SmartCityApplication extends Application {
	public static final String TAG = SmartCityCommon.SMART_CITY_APP_TAG;
	private ImageLoaderUtils mImageLoader = null;
	public static final String PREFS = "";
	private static SmartCityApplication instance = null;
	private static Context context = null;
	private Boolean mReachable = null;
	private final static String SERVER_URL = "";

	public static SmartCityApplication getInstance() {
		if (instance == null) {
			throw new IllegalStateException("Application not created yet!");
		}

		return instance;
	}
	
	
	@Override
	public void onCreate() {
		instance = this;
		context = getApplicationContext();
		if (android.os.Build.VERSION.SDK_INT > 10) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}

		GpsLocationUtils.initLocationManager();
		// applyPreferences();
	}

	public static Context getAppContext() {
		return context;
	}
	
	/**
	 * @return the context
	 */
	public static Context getContext() {
		return context;
	}


	/**
	 * @param context the context to set
	 */
	public static void setContext(Context context) {
		SmartCityApplication.context = context;
	}


	public static void setAppContext(Context context) {
		setContext(context);
	}

	/**
	 * Public accessor for image-loader, so all activities all use the same
	 * instance.
	 * 
	 * @return ImageLoader
	 */
	public ImageLoaderUtils getImageLoader() {
		if (mImageLoader == null) {
			mImageLoader = new ImageLoaderUtils(this);
		}

		return mImageLoader;
	}
	@Override
	public void onTerminate() {
		super.onTerminate();
	}

}